//
//  CourseForecastDetailViewController.m
//  ECBBusinessCamp
//
//  Created by rimi on 16/6/18.
//  Copyright © 2016年 邓毕华. All rights reserved.
//

#import "CourseForecastDetailViewController.h"


@interface CourseForecastDetailViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imagev;

@property (weak, nonatomic) IBOutlet UILabel *titleName;

@property (weak, nonatomic) IBOutlet UILabel *actor;

@property (weak, nonatomic) IBOutlet UILabel *times;

@property (weak, nonatomic) IBOutlet UILabel *address;

@property (weak, nonatomic) IBOutlet UILabel *forecast;

@property (weak, nonatomic) IBOutlet UILabel *personNum;

@property (weak, nonatomic) IBOutlet UIButton *escBtn;

@property (weak, nonatomic) IBOutlet UIButton *shareBtn;

@property (weak, nonatomic) IBOutlet UIButton *report;//报到

@property (nonatomic,strong) NSMutableDictionary *applyDataload;
@property (nonatomic,strong) NSString *classId;

@property (nonatomic,strong) CourseForecastSharesViewController *shareVc;

@end

@implementation CourseForecastDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString *url = BASEURLAPPEND(_detailDicSource[@"pic"]);
    [NSURL URLWithString:url];
    [_imagev sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"user_default"]];
    _titleName.text = _detailDicSource[@"className"];
    _actor.text =  [NSString stringWithFormat:@"%@%@",@"讲师:",_detailDicSource[@"teacherName"]];
    _times.text = [NSString stringWithFormat:@"%@%@",@"时间:",[NSDate dateWithTimeIntervalSince1970:[_detailDicSource[@"startTime"][@"time"] doubleValue]/1000]];
    _address.text = [NSString stringWithFormat:@"%@%@",@"地点:",_detailDicSource[@"place"]];
    _forecast.text = _detailDicSource[@"desce"];
    
    NSInteger totalNum = [_detailDicSource[@"totalNum"] integerValue];
    NSInteger currentNum = [_detailDicSource[@"currentNum"] integerValue];
    _personNum.text = [NSString stringWithFormat:@"已有%ld人报名，剩余%ld个名额",currentNum,(totalNum - currentNum)];
    _classId = _detailDicSource[@"id"];

    _escBtn.tag = TAG_BTN;
    _shareBtn.tag = TAG_BTN + 1;
    _report.tag = TAG_BTN + 2;

}


//点击事件
- (IBAction)actionBtn:(UIButton *)sender {
    
    switch (sender.tag - TAG_BTN) {
        case 0:
            //退出
             NSLog(@"1");
            [self animationz:self.view];
           break;
        case 1:
            //分享
            _shareVc = [self.storyboard instantiateViewControllerWithIdentifier:@"CourseForecastSharesViewController"];
            [self addChildViewController:_shareVc];
            [self.view addSubview:_shareVc.view];
            
            break;
        case 2:
            //报名
            [self applyData];
            break;
            
        default:
            break;
    }
}

- (void)applyData{
    
    _applyDataload = [NSMutableDictionary dictionaryWithObjects:@[_classId,[LoginUserInfo defaultUserInfo].userid] forKeys:@[@"classId",@"id"]];
    
    [[NetTool sharedTool] requestMethod:POST loadingMsg:@"加载中..." url:BASEURLAPPEND(COURSEFORECASRAPPLY_URL) parameters:_applyDataload finish:^(id responseObject, NSError *error) {
        NSNumber * status = responseObject[@"status"];
        NSLog(@"%@",status);
        if ([status intValue] == 1) {
            [MBProgressHUD showSuccess:@"报名成功"];
        }else{
            [MBProgressHUD showError:@"报名失败"];
        }
     
    }];
}


#pragma mark -- 返回动画 --
#pragma mark --
- (void)animationz:(UIView *)someoneview{
    
    
    [UIView animateWithDuration:1 animations:^{
        NSLog(@"--");
        someoneview.center = CGPointMake(self.view.center.x * 3, self.view.center.y);
    } completion:^(BOOL finished) {
 
        [self.view removeFromSuperview];
        [self removeFromParentViewController];
        NSLog(@"返回动画");
    }];
   
    
    
}


@end
